<?php
declare (strict_types = 1);

namespace app\api\controller;

use app\api\BaseController;
use app\middleware\AuthOperate;
use think\facade\Db;

class Index extends BaseController
{
    protected $table = 'submit';
    public function index()
    {
        return '您好！这是一个[api]示例应用';
    }
    public function getSubmit(){
        /**
        CREATE TABLE `submit` (
        `submit_id` int(11) NOT NULL,
        `submit_ago` varchar(100) NOT NULL,
        `submit_name` varchar(15) NOT NULL,
        `submit_phone` bigint(11) NOT NULL,
        `submit_time` datetime NOT NULL,
        `check_time` date NOT NULL,
        PRIMARY KEY (`submit_id`)
        ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;

        --
        -- 转存表中的数据 `submit`
        --

        INSERT INTO `submit` (`submit_id`, `submit_ago`, `submit_name`, `submit_phone`, `submit_time`, `check_time`) VALUES
        (6, '30岁以下', '111', 15555555555, '2022-10-17 17:09:35', '2022-10-17'),
        (2, '50以上', '牛皮', 18845455445, '2022-10-11 16:52:25', '2022-10-10'),
        (3, '50以上', '老王', 18877848545, '2022-10-12 09:53:18', '2022-10-12'),
        (4, '30岁以下', '米奇', 16797994664, '2022-10-12 15:35:49', '2022-10-12'),
        (5, '50以上', '川普', 19949976464, '2022-10-12 16:44:42', '2022-10-12'),
        (7, '30岁以下', '陈会', 18826964910, '2022-10-22 14:35:32', '2022-10-22'),
        (8, '30-40岁', '牛中文', 13406293548, '2022-10-24 15:13:47', '2022-10-24');

         **/
        $data = request()->param();
        $page = (int)$data['page'];
        $limit = (int)$data['limit'];
        $result2 = [];
        $result2['submit_name'] = ['=',$data['submit_name']??''];
        $result2['submit_phone'] = ['=',$data['submit_phone']??''];
        $result2['submit_ago'] = ['=',$data['submit_ago']??''];
        $result2['submit_time'] =  ['between', [$data['date1'] ?? '',$data['date2'] ?? '']];
        $result2['del_status'] = ['=',0];
        $this->getData($this->table,$page,$limit,$result2);

    }
    public function delList(){
        $data = request()->param();
        $this->delData($this->table,['submit_id'=>$data['submit_id']]);
    }
	public function delAllList(){

        $this->delAllData($this->table,[['submit_id','>',0]]);

//        if($checkToken['status']==10001){
//           $data = request()->param();
//           $token = request()->header('token');
//           $checkToken = checkToken($token);
//           $uid = $checkToken['data']->uid;
//           $admin_password = Db::table('admin')->where('admin_id',$uid)->value('admin_password');
//           $check_data = checkPassword($data['admin_password'],$admin_password);
//            if($check_data['status']==500){
//                return json(['status'=>500,'msg'=>'密码错误！']);
//            }
//            $all_del =  Db::table('submit')->where('submit_id','>',0)->update(['del_status'=>1]);
//            if($all_del){
//                return json(['status'=>200,'msg'=>'全部删除成功！']);
//            }else{
//                return json(['status'=>500,'msg'=>'全部删除失败！']);
//            }
//
//        }else{
//            return json(['status'=>501,'msg'=>$checkToken['data']]);
//        }
    }
}
